package com.xinxing.city.recovery.utils;

import android.content.Context;
import android.os.Handler;
import android.util.Log;

import com.xinxing.city.recovery.APPRuntime;
import com.xinxing.city.recovery.DI;
import com.xinxing.city.recovery.entitys.BucketType;
import com.xinxing.city.recovery.interfaces.ICallBackWeight;
import com.xinxing.city.recovery.interfaces.IDeviceKernel;
import com.xinxing.city.recovery.interfaces.ISerialSendReceiveData;

import java.util.List;

public class GetWeight {
    private Context context;
    private Handler handler = new Handler();
    private Runnable runnable;
    private IDeviceKernel deviceKernel;
    private ISerialSendReceiveData serial;

    int doorNum = 1;
    public GetWeight(Context context){
        this.context = context;
        deviceKernel = DI.getInstance(IDeviceKernel.class);
        serial = deviceKernel.getSerial();

    }
    public void getWeight(){
        doorNum =1;
        Log.e("yujs",doorNum+"开始初始化重量；");
        runnable = new Runnable() {
            @Override
            public void run() {
                Log.e("yujs",doorNum+"初始化重量2");
                serial.getWeight(doorNum, new ICallBackWeight() {
                    @Override
                    public void setWeight(int num, long weight) {
                        Log.e("yujs",doorNum+"初始化重量；"+weight);
                        doorNum++;
                        if(doorNum<5) {
                            handler.postDelayed(runnable, 50);
                        }
                    }
                });
            }
        };
        handler.postDelayed(runnable,50);
    }
}
